/**
 * This is a generated class and is not intended for modification.  To customize behavior
 * of this value object you may modify the generated sub-class of this class - VoPoHeaderSearch.as.
 */

package com.model.valueObjects
{
import com.adobe.fiber.services.IFiberManagingService;
import com.adobe.fiber.util.FiberUtils;
import com.adobe.fiber.valueobjects.IValueObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.ChangeWatcher;
import mx.events.PropertyChangeEvent;
import mx.validators.ValidationResult;

import flash.net.registerClassAlias;
import flash.net.getClassByAlias;
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.valueobjects.IPropertyIterator;
import com.adobe.fiber.valueobjects.AvailablePropertyIterator;

use namespace model_internal;

[ExcludeClass]
public class _Super_VoPoHeaderSearch extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
{
    model_internal static function initRemoteClassAliasSingle(cz:Class) : void
    {
        try
        {
            if (flash.net.getClassByAlias("VoPoHeaderSearch") == null)
            {
                flash.net.registerClassAlias("VoPoHeaderSearch", cz);
            }
        }
        catch (e:Error)
        {
            flash.net.registerClassAlias("VoPoHeaderSearch", cz);
        }
    }

    model_internal static function initRemoteClassAliasAllRelated() : void
    {
    }

    model_internal var _dminternal_model : _VoPoHeaderSearchEntityMetadata;

    /**
     * properties
     */
    private var _internal_total_amount : Number;
    private var _internal_total_qty : int;
    private var _internal_po_status : String;
    private var _internal_gst_amount : Number;
    private var _internal_po_id : String;
    private var _internal_po_remarks : String;
    private var _internal_expected_datetime : String;
    private var _internal_tot_balance_qty : int;
    private var _internal_po_issue_date : String;
    private var _internal_po_serialnumber : int;
    private var _internal_currency_name : String;
    private var _internal_sgd_amount : Number;
    private var _internal_sgd_total_amount : Number;
    private var _internal_supplier : String;

    private static var emptyArray:Array = new Array();

    // Change this value according to your application's floating-point precision
    private static var epsilon:Number = 0.0001;

    /**
     * derived property cache initialization
     */
    model_internal var _cacheInitialized_isValid:Boolean = false;

    model_internal var _changeWatcherArray:Array = new Array();

    public function _Super_VoPoHeaderSearch()
    {
        _model = new _VoPoHeaderSearchEntityMetadata(this);

        // Bind to own data properties for cache invalidation triggering
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "po_status", model_internal::setterListenerPo_status));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "po_id", model_internal::setterListenerPo_id));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "po_remarks", model_internal::setterListenerPo_remarks));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "expected_datetime", model_internal::setterListenerExpected_datetime));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "po_issue_date", model_internal::setterListenerPo_issue_date));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "currency_name", model_internal::setterListenerCurrency_name));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "supplier", model_internal::setterListenerSupplier));

    }

    /**
     * data property getters
     */

    [Bindable(event="propertyChange")]
    public function get total_amount() : Number
    {
        return _internal_total_amount;
    }

    [Bindable(event="propertyChange")]
    public function get total_qty() : int
    {
        return _internal_total_qty;
    }

    [Bindable(event="propertyChange")]
    public function get po_status() : String
    {
        return _internal_po_status;
    }

    [Bindable(event="propertyChange")]
    public function get gst_amount() : Number
    {
        return _internal_gst_amount;
    }

    [Bindable(event="propertyChange")]
    public function get po_id() : String
    {
        return _internal_po_id;
    }

    [Bindable(event="propertyChange")]
    public function get po_remarks() : String
    {
        return _internal_po_remarks;
    }

    [Bindable(event="propertyChange")]
    public function get expected_datetime() : String
    {
        return _internal_expected_datetime;
    }

    [Bindable(event="propertyChange")]
    public function get tot_balance_qty() : int
    {
        return _internal_tot_balance_qty;
    }

    [Bindable(event="propertyChange")]
    public function get po_issue_date() : String
    {
        return _internal_po_issue_date;
    }

    [Bindable(event="propertyChange")]
    public function get po_serialnumber() : int
    {
        return _internal_po_serialnumber;
    }

    [Bindable(event="propertyChange")]
    public function get currency_name() : String
    {
        return _internal_currency_name;
    }

    [Bindable(event="propertyChange")]
    public function get sgd_amount() : Number
    {
        return _internal_sgd_amount;
    }

    [Bindable(event="propertyChange")]
    public function get sgd_total_amount() : Number
    {
        return _internal_sgd_total_amount;
    }

    [Bindable(event="propertyChange")]
    public function get supplier() : String
    {
        return _internal_supplier;
    }

    /**
     * data property setters
     */

    public function set total_amount(value:Number) : void
    {
        var oldValue:Number = _internal_total_amount;
        if (isNaN(_internal_total_amount) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_total_amount = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "total_amount", oldValue, _internal_total_amount));
        }
    }

    public function set total_qty(value:int) : void
    {
        var oldValue:int = _internal_total_qty;
        if (oldValue !== value)
        {
            _internal_total_qty = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "total_qty", oldValue, _internal_total_qty));
        }
    }

    public function set po_status(value:String) : void
    {
        var oldValue:String = _internal_po_status;
        if (oldValue !== value)
        {
            _internal_po_status = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "po_status", oldValue, _internal_po_status));
        }
    }

    public function set gst_amount(value:Number) : void
    {
        var oldValue:Number = _internal_gst_amount;
        if (isNaN(_internal_gst_amount) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_gst_amount = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "gst_amount", oldValue, _internal_gst_amount));
        }
    }

    public function set po_id(value:String) : void
    {
        var oldValue:String = _internal_po_id;
        if (oldValue !== value)
        {
            _internal_po_id = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "po_id", oldValue, _internal_po_id));
        }
    }

    public function set po_remarks(value:String) : void
    {
        var oldValue:String = _internal_po_remarks;
        if (oldValue !== value)
        {
            _internal_po_remarks = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "po_remarks", oldValue, _internal_po_remarks));
        }
    }

    public function set expected_datetime(value:String) : void
    {
        var oldValue:String = _internal_expected_datetime;
        if (oldValue !== value)
        {
            _internal_expected_datetime = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "expected_datetime", oldValue, _internal_expected_datetime));
        }
    }

    public function set tot_balance_qty(value:int) : void
    {
        var oldValue:int = _internal_tot_balance_qty;
        if (oldValue !== value)
        {
            _internal_tot_balance_qty = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "tot_balance_qty", oldValue, _internal_tot_balance_qty));
        }
    }

    public function set po_issue_date(value:String) : void
    {
        var oldValue:String = _internal_po_issue_date;
        if (oldValue !== value)
        {
            _internal_po_issue_date = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "po_issue_date", oldValue, _internal_po_issue_date));
        }
    }

    public function set po_serialnumber(value:int) : void
    {
        var oldValue:int = _internal_po_serialnumber;
        if (oldValue !== value)
        {
            _internal_po_serialnumber = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "po_serialnumber", oldValue, _internal_po_serialnumber));
        }
    }

    public function set currency_name(value:String) : void
    {
        var oldValue:String = _internal_currency_name;
        if (oldValue !== value)
        {
            _internal_currency_name = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_name", oldValue, _internal_currency_name));
        }
    }

    public function set sgd_amount(value:Number) : void
    {
        var oldValue:Number = _internal_sgd_amount;
        if (isNaN(_internal_sgd_amount) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_sgd_amount = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "sgd_amount", oldValue, _internal_sgd_amount));
        }
    }

    public function set sgd_total_amount(value:Number) : void
    {
        var oldValue:Number = _internal_sgd_total_amount;
        if (isNaN(_internal_sgd_total_amount) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_sgd_total_amount = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "sgd_total_amount", oldValue, _internal_sgd_total_amount));
        }
    }

    public function set supplier(value:String) : void
    {
        var oldValue:String = _internal_supplier;
        if (oldValue !== value)
        {
            _internal_supplier = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "supplier", oldValue, _internal_supplier));
        }
    }

    /**
     * Data property setter listeners
     *
     * Each data property whose value affects other properties or the validity of the entity
     * needs to invalidate all previously calculated artifacts. These include:
     *  - any derived properties or constraints that reference the given data property.
     *  - any availability guards (variant expressions) that reference the given data property.
     *  - any style validations, message tokens or guards that reference the given data property.
     *  - the validity of the property (and the containing entity) if the given data property has a length restriction.
     *  - the validity of the property (and the containing entity) if the given data property is required.
     */

    model_internal function setterListenerPo_status(value:flash.events.Event):void
    {
        _model.invalidateDependentOnPo_status();
    }

    model_internal function setterListenerPo_id(value:flash.events.Event):void
    {
        _model.invalidateDependentOnPo_id();
    }

    model_internal function setterListenerPo_remarks(value:flash.events.Event):void
    {
        _model.invalidateDependentOnPo_remarks();
    }

    model_internal function setterListenerExpected_datetime(value:flash.events.Event):void
    {
        _model.invalidateDependentOnExpected_datetime();
    }

    model_internal function setterListenerPo_issue_date(value:flash.events.Event):void
    {
        _model.invalidateDependentOnPo_issue_date();
    }

    model_internal function setterListenerCurrency_name(value:flash.events.Event):void
    {
        _model.invalidateDependentOnCurrency_name();
    }

    model_internal function setterListenerSupplier(value:flash.events.Event):void
    {
        _model.invalidateDependentOnSupplier();
    }


    /**
     * valid related derived properties
     */
    model_internal var _isValid : Boolean;
    model_internal var _invalidConstraints:Array = new Array();
    model_internal var _validationFailureMessages:Array = new Array();

    /**
     * derived property calculators
     */

    /**
     * isValid calculator
     */
    model_internal function calculateIsValid():Boolean
    {
        var violatedConsts:Array = new Array();
        var validationFailureMessages:Array = new Array();

        var propertyValidity:Boolean = true;
        if (!_model.po_statusIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_po_statusValidationFailureMessages);
        }
        if (!_model.po_idIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_po_idValidationFailureMessages);
        }
        if (!_model.po_remarksIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_po_remarksValidationFailureMessages);
        }
        if (!_model.expected_datetimeIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_expected_datetimeValidationFailureMessages);
        }
        if (!_model.po_issue_dateIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_po_issue_dateValidationFailureMessages);
        }
        if (!_model.currency_nameIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_currency_nameValidationFailureMessages);
        }
        if (!_model.supplierIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_supplierValidationFailureMessages);
        }

        model_internal::_cacheInitialized_isValid = true;
        model_internal::invalidConstraints_der = violatedConsts;
        model_internal::validationFailureMessages_der = validationFailureMessages;
        return violatedConsts.length == 0 && propertyValidity;
    }

    /**
     * derived property setters
     */

    model_internal function set isValid_der(value:Boolean) : void
    {
        var oldValue:Boolean = model_internal::_isValid;
        if (oldValue !== value)
        {
            model_internal::_isValid = value;
            _model.model_internal::fireChangeEvent("isValid", oldValue, model_internal::_isValid);
        }
    }

    /**
     * derived property getters
     */

    [Transient]
    [Bindable(event="propertyChange")]
    public function get _model() : _VoPoHeaderSearchEntityMetadata
    {
        return model_internal::_dminternal_model;
    }

    public function set _model(value : _VoPoHeaderSearchEntityMetadata) : void
    {
        var oldValue : _VoPoHeaderSearchEntityMetadata = model_internal::_dminternal_model;
        if (oldValue !== value)
        {
            model_internal::_dminternal_model = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "_model", oldValue, model_internal::_dminternal_model));
        }
    }

    /**
     * methods
     */


    /**
     *  services
     */
    private var _managingService:com.adobe.fiber.services.IFiberManagingService;

    public function set managingService(managingService:com.adobe.fiber.services.IFiberManagingService):void
    {
        _managingService = managingService;
    }

    model_internal function set invalidConstraints_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_invalidConstraints;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_invalidConstraints = value;
            _model.model_internal::fireChangeEvent("invalidConstraints", oldValue, model_internal::_invalidConstraints);
        }
    }

    model_internal function set validationFailureMessages_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_validationFailureMessages;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_validationFailureMessages = value;
            _model.model_internal::fireChangeEvent("validationFailureMessages", oldValue, model_internal::_validationFailureMessages);
        }
    }

    model_internal var _doValidationCacheOfPo_status : Array = null;
    model_internal var _doValidationLastValOfPo_status : String;

    model_internal function _doValidationForPo_status(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfPo_status != null && model_internal::_doValidationLastValOfPo_status == value)
           return model_internal::_doValidationCacheOfPo_status ;

        _model.model_internal::_po_statusIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isPo_statusAvailable && _internal_po_status == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "po_status is required"));
        }

        model_internal::_doValidationCacheOfPo_status = validationFailures;
        model_internal::_doValidationLastValOfPo_status = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfPo_id : Array = null;
    model_internal var _doValidationLastValOfPo_id : String;

    model_internal function _doValidationForPo_id(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfPo_id != null && model_internal::_doValidationLastValOfPo_id == value)
           return model_internal::_doValidationCacheOfPo_id ;

        _model.model_internal::_po_idIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isPo_idAvailable && _internal_po_id == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "po_id is required"));
        }

        model_internal::_doValidationCacheOfPo_id = validationFailures;
        model_internal::_doValidationLastValOfPo_id = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfPo_remarks : Array = null;
    model_internal var _doValidationLastValOfPo_remarks : String;

    model_internal function _doValidationForPo_remarks(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfPo_remarks != null && model_internal::_doValidationLastValOfPo_remarks == value)
           return model_internal::_doValidationCacheOfPo_remarks ;

        _model.model_internal::_po_remarksIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isPo_remarksAvailable && _internal_po_remarks == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "po_remarks is required"));
        }

        model_internal::_doValidationCacheOfPo_remarks = validationFailures;
        model_internal::_doValidationLastValOfPo_remarks = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfExpected_datetime : Array = null;
    model_internal var _doValidationLastValOfExpected_datetime : String;

    model_internal function _doValidationForExpected_datetime(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfExpected_datetime != null && model_internal::_doValidationLastValOfExpected_datetime == value)
           return model_internal::_doValidationCacheOfExpected_datetime ;

        _model.model_internal::_expected_datetimeIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isExpected_datetimeAvailable && _internal_expected_datetime == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "expected_datetime is required"));
        }

        model_internal::_doValidationCacheOfExpected_datetime = validationFailures;
        model_internal::_doValidationLastValOfExpected_datetime = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfPo_issue_date : Array = null;
    model_internal var _doValidationLastValOfPo_issue_date : String;

    model_internal function _doValidationForPo_issue_date(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfPo_issue_date != null && model_internal::_doValidationLastValOfPo_issue_date == value)
           return model_internal::_doValidationCacheOfPo_issue_date ;

        _model.model_internal::_po_issue_dateIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isPo_issue_dateAvailable && _internal_po_issue_date == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "po_issue_date is required"));
        }

        model_internal::_doValidationCacheOfPo_issue_date = validationFailures;
        model_internal::_doValidationLastValOfPo_issue_date = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfCurrency_name : Array = null;
    model_internal var _doValidationLastValOfCurrency_name : String;

    model_internal function _doValidationForCurrency_name(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfCurrency_name != null && model_internal::_doValidationLastValOfCurrency_name == value)
           return model_internal::_doValidationCacheOfCurrency_name ;

        _model.model_internal::_currency_nameIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isCurrency_nameAvailable && _internal_currency_name == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "currency_name is required"));
        }

        model_internal::_doValidationCacheOfCurrency_name = validationFailures;
        model_internal::_doValidationLastValOfCurrency_name = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfSupplier : Array = null;
    model_internal var _doValidationLastValOfSupplier : String;

    model_internal function _doValidationForSupplier(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfSupplier != null && model_internal::_doValidationLastValOfSupplier == value)
           return model_internal::_doValidationCacheOfSupplier ;

        _model.model_internal::_supplierIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isSupplierAvailable && _internal_supplier == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "supplier is required"));
        }

        model_internal::_doValidationCacheOfSupplier = validationFailures;
        model_internal::_doValidationLastValOfSupplier = value;

        return validationFailures;
    }
    

}

}
